package offer;

import java.util.Deque;
import java.util.LinkedList;

/**
 * 描述:剑指 Offer 09. 用两个栈实现队列
 *
 * @author Madison You
 * @created 21:17
 */
public class Easy_09_CQueue {

    public static void main(String[] args) {
        Easy_09_CQueue easy_09_cQueue = new Easy_09_CQueue();
        easy_09_cQueue.appendTail(3);
        easy_09_cQueue.deleteHead();
        easy_09_cQueue.deleteHead();
    }

    private Deque<Integer> deque1 = null;
    private Deque<Integer> deque2 = null;

    public Easy_09_CQueue() {
        deque1 = new LinkedList<>();
        deque2 = new LinkedList<>();
    }

    public void appendTail(int value) {
        deque1.push(value);
    }

    public int deleteHead() {
        if (deque2.isEmpty()) {
            if (deque1.isEmpty()) {
                return -1;
            }
            while (!deque1.isEmpty()) {
                deque2.push(deque1.pop());
            }
            return deque2.pop();
        } else {
            return deque2.pop();
        }
    }
}
